# 给予其点的坐标，并设置好r的长度，可以做到不错的热图效果

import urllib.request
from pyheatmap.heatmap import HeatMap
import sys
from PIL import Image

def main():
    data = []
    # download test data
    url="https://raw.github.com/oldj/pyheatmap/master/examples/test_data.txt"
    sdata_bytes = urllib.request.urlopen(url).read()
    sdata_str = str(sdata_bytes, encoding="utf-8")
    sdata = sdata_str.split("\n")
    data = []

    for ln in sdata:
        a = ln.split(",")
        if len(a) != 2:
            continue
        a = [int(i) for i in a]
        data.append(a)

    hm = HeatMap(data)
    hm.clickmap(save_as="I:/pyCharmProjectSet/deepLearning/otherWay/data/Heat_Map/hit.png")
    hm.heatmap(save_as="I:/pyCharmProjectSet/deepLearning/otherWay/data/Heat_Map/heat.png")

def example0():
    f = open("../../../data/Heat_Map/tab_point2.txt")
    # testread = f.read()
    sdata_str = f.read()
    sdata = sdata_str.split("\n")
    data = []

    for ln in sdata:
        a = ln.split(",")
        if len(a) != 2:
            continue
        a = [int(i) for i in a]
        data.append(a)

    hm = HeatMap(data)
    base_img = 'I:/pyCharmProjectSet/deepLearning/otherWay/data/Heat_Map/fullImage.jpg'
    hm.clickmap(save_as="I:/pyCharmProjectSet/deepLearning/otherWay/data/Heat_Map/hit0.png")
    hm.heatmap(save_as="I:/pyCharmProjectSet/deepLearning/otherWay/data/Heat_Map/heat0.png",base=base_img,r=50)


def example1():
    f = open("../../../data/Heat_Map/test3.txt")
    # testread = f.read()
    sdata_str = f.read()
    sdata = sdata_str.split("\n")
    data = []

    for ln in sdata:
        a = ln.split(",")
        if len(a) != 3:
            continue
        b = []
        a_length = len(a)
        for i in range(a_length):
            if i == 2:
                b.append(float(a[i]))
            else:
                b.append(int(a[i]))
        data.append(b)

    hm = HeatMap(data)
    # hm.clickmap(save_as="I:/pyCharmProjectSet/deepLearning/otherWay/data/Heat_Map/hit3.png")
    hm.heatmap(save_as="I:/pyCharmProjectSet/deepLearning/otherWay/data/Heat_Map/heat3.png")

def example2():

    # data_1 = loadDataFromFile("test_data.txt")
    #
    # data_2 = loadDataFromFile("test_data2.txt")

    txt = open("I:/pyCharmProjectSet/deepLearning/otherWay/data/Heat_Map/test.txt",'r')
    sdata_str = txt.read()

    sdata = sdata_str.split("\n")
    data = []

    for ln in sdata:
        a = ln.split(",")
        if len(a) != 2:
            continue
        a = [int(i) for i in a]
        data.append(a)

    base_img = "I:/pyCharmProjectSet/deepLearning/otherWay/data/Heat_Map/20180503172909.jpg"

    hm2 = HeatMap(data)

    # hm = HeatMap(data_1)
    #
    # hit_img = hm.clickmap()

    # test = Image.open(base_img)


    # hit_img2 = hm2.clickmap(base=base_img, color=(0, 0, 255, 255))
    hit_img2 = hm2.heatmap(base=base_img)

    hit_img2.save("I:/pyCharmProjectSet/deepLearning/otherWay/data/Heat_Map/hit2.png")


def example3():

    # data_1 = loadDataFromFile("test_data.txt")
    #
    # data_2 = loadDataFromFile("test_data2.txt")

    data_2 = open("I:/pyCharmProjectSet/deepLearning/otherWay/data/Heat_Map/test.txt",'r')


    data_1 = open("I:/pyCharmProjectSet/deepLearning/otherWay/data/Heat_Map/20180503172909.jpg",'r')

    hm2 = HeatMap(data_2)

    hm = HeatMap(data_1)

    hit_img = hm.clickmap()



    hit_img2 = hm2.clickmap(base=hit_img, color=(0, 0, 255, 255))

    hit_img2.save("I:/pyCharmProjectSet/deepLearning/otherWay/data/Heat_Map/hit2.png")

if __name__ == "__main__":
    # main()
    example0()
    # example1()
    # example2()